package com.ruoyi.radar.cal;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class PlyHeader {
    private String format;
    private Map<String, Integer> elementCounts = new HashMap<>();
    private Map<String, Map<String, String>> elementProperties = new HashMap<>();

    public void parseHeader(String filePath) throws IOException {
        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = reader.readLine()) != null && !line.equals("end_header")) {
                String[] tokens = line.split("\\s+");
                switch (tokens[0]) {
                    case "format":
                        format = tokens[1];
                        break;
                    case "element":
                        elementCounts.put(tokens[1], Integer.parseInt(tokens[2]));
                        elementProperties.put(tokens[1], new HashMap<>());
                        break;
                    case "property":
                        Map<String, String> properties = elementProperties.getOrDefault(tokens[2],new HashMap<>());
                        properties.put(tokens[2], tokens[1]);
                        break;
                }
            }
        }
    }

    public String getFormat() {
        return format;
    }

    public int getElementCount(String element) {
        return elementCounts.getOrDefault(element, 0);
    }

    public Map<String, String> getElementProperties(String element) {
        return elementProperties.get(element);
    }
}  